// pages/product/list/list.js
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    categoryId: 0,
    productList: [],
    category: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.cid)
    this.setData({
      categoryId: options.cid
    })
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.initApp()
  },

  /**
   * init
   */
  initApp: function() {
    let that = this
    wx.showLoading({
      mask: true,
      title: app.globalData.loadText,
    })
    wx.request({
      url: app.globalData.hostAPI + '/v1/product/get-by-category-id?cid=' + that.data.categoryId,
      success: res => {
        if(res.data.status === 1) {
          that.setData({
            category: res.data.data.category,
            productList: res.data.data.product
          })
          wx.hideLoading()
        }
      }
    })
  },

  /**
   * goProDetail
   */
  goProDetail: function(e) {
    let that = this,
        pid = e.currentTarget.id
    wx.navigateTo({
      url: '../product?productID=' + pid,
    })
  }
})